package com.pai4j.domain.dto.bot;


import lombok.Data;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.util.CollectionUtils;

import java.util.List;


/**
 * {
 * 	"function": "SUMMARY_CHAT_MESSAGE",
 * 	"parameters": {
 * 		        {
 * 			"name": "sourceUsername",
 * 			"value": "我",
 * 			"type": "String"
 *        },
 *        {
 * 			"name": "targetUsername",
 * 			"value": "张三",
 * 			"type": "String"
 *        },
 *        {
 * 			"name": "startTime",
 * 			"value": 1746864297786,
 * 			"type": "Long"
 *        },
 *        {
 * 			"name": "endTime",
 * 			"value": 1746864897786,
 * 			"type": "Long"
 *        }    * 	}
 * }
 */
@Data
public class LLMParameterDTO {

    private String function;

    private List<PluginParameterDTO> parameters;

    /**
     * 插件接口信息
     */
    private BotPluginDTO plugin;

    public Object getParameterValue(String parameterName) {
        if (CollectionUtils.isEmpty(parameters)) {
            return null;
        }
        for (PluginParameterDTO pluginParameterDTO : parameters) {
            if (ObjectUtils.equals(pluginParameterDTO.getName(), parameterName)) {
                return pluginParameterDTO.getValue();
            }
        }
        return null;
    }

    public void resetParameterValue(String parameterName, String newParameterName, String newParameterValue) {
        if (CollectionUtils.isEmpty(parameters)) {
            return;
        }
        for (PluginParameterDTO pluginParameterDTO : parameters) {
            if (ObjectUtils.equals(pluginParameterDTO.getName(), parameterName)) {
                pluginParameterDTO.setName(newParameterName);
                pluginParameterDTO.setValue(newParameterValue);
            }
        }
    }
}
